package com.dhcc.bpm.modules.safe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.common.text.Convert;
import com.dhcc.bpm.modules.safe.entity.OrgaControl;
import com.dhcc.bpm.modules.safe.mapper.OrgaControlMapper;
import com.dhcc.bpm.modules.safe.service.IOrgaControlService;
import com.dhcc.bpm.modules.safe.vo.OrgaControlVO;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OrgaControlServiceImpl
 * @Description API访问控制机构关联表 服务实现类
 * @Author daina
 * @Date 2020/2/21 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@Service("opc_orga_control")
public class OrgaControlServiceImpl extends ServiceImpl<OrgaControlMapper, OrgaControl> implements IOrgaControlService {

	@Autowired
	private OrgaControlMapper orgaControlMapper;

	@Override
	public IPage<OrgaControlVO> selectOrgaControlPage(IPage<OrgaControlVO> page, OrgaControlVO orgaControl) {
		return page.setRecords(baseMapper.selectOrgaControlPage(page, orgaControl));
	}

	@Override
	public int deleteOrgas(Long opcControlId, String ids) {
		return orgaControlMapper.deleteOrgas(opcControlId, Convert.toLongArray(ids));
	}

	@Override
	public Boolean batchControllerOrga(Long opcControlId, String ids) {
		List<Long> orgaIds = Func.toLongList(ids);
		ArrayList<OrgaControl> list = new ArrayList<>();
		orgaIds.forEach(orgaId->{
			OrgaControl orgaControl = new OrgaControl();
			orgaControl.setOpcOrgaId(orgaId);
			orgaControl.setOpcControlId(opcControlId);
			list.add(orgaControl);
		});
		return saveBatch(list);

	}
}
